package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;

import org.jvnet.substance.SubstanceLookAndFeel;

import util.Util;

public class Principal extends JApplet implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private PanelLogeo panelLogeo;
	private PanelPrincipal panelPrincipal;

	private int k;

	public void init() {
		SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.CremeSkin");

		setLayout(null);

		panelLogeo = new PanelLogeo();
		panelLogeo.btnEntrar.addActionListener(this);
		panelLogeo.setVisible(true);

		panelPrincipal = new PanelPrincipal();
		panelPrincipal.btnSalir.addActionListener(this);

		add(panelLogeo);
		add(panelPrincipal);

		k = 0;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == panelLogeo.btnEntrar) {

			if (panelLogeo.logeo()) {
				panelLogeo.setVisible(false);
				panelPrincipal.setVisible(true);
				Util.Mensaje(null, "Bienvenido al sistema", 1);
				k = 0;
			} else
				k++;

			if (k >= 3) {
				panelLogeo.bloquear();
			}

		} else if (e.getSource() == panelPrincipal.btnSalir) {
			panelPrincipal.salir();
			panelLogeo.setVisible(true);
		}

	}
	
	
}
